

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/Mine.jpg">
  <link rel="icon" href="/img/Mine.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Chiam">
  <meta name="keywords" content="算法，安全">
  
    <meta name="description" content="『算法-ACM 竞赛-动态规划-树形 DP』洛谷 2016 战略游戏（树形 DP）洛谷 2016 战略游戏（树形 DP）题目描述Bob 喜欢玩电脑游戏，特别是战略游戏。但是他经常无法找到快速玩过游戏的办法。现在他有个问题。 他要建立一个古城堡，城堡中的路形成一棵树。他要在这棵树的结点上放置最少数目的士兵，使得这些士兵能了望到所有的路。 注意，某个士兵在一个结点上时，与该结点相连的所有边将都可以被了">
<meta property="og:type" content="article">
<meta property="og:title" content="『算法-ACM竞赛-动态规划-树形DP』洛谷2016战略游戏（树形DP）">
<meta property="og:url" content="http://example.com/2023/12/06/%E3%80%8E%E7%AE%97%E6%B3%95-ACM%E7%AB%9E%E8%B5%9B-%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92-%E6%A0%91%E5%BD%A2DP%E3%80%8F%E6%B4%9B%E8%B0%B72016%E6%88%98%E7%95%A5%E6%B8%B8%E6%88%8F%EF%BC%88%E6%A0%91%E5%BD%A2DP%EF%BC%89/index.html">
<meta property="og:site_name" content="Chiam 的个人主页">
<meta property="og:description" content="『算法-ACM 竞赛-动态规划-树形 DP』洛谷 2016 战略游戏（树形 DP）洛谷 2016 战略游戏（树形 DP）题目描述Bob 喜欢玩电脑游戏，特别是战略游戏。但是他经常无法找到快速玩过游戏的办法。现在他有个问题。 他要建立一个古城堡，城堡中的路形成一棵树。他要在这棵树的结点上放置最少数目的士兵，使得这些士兵能了望到所有的路。 注意，某个士兵在一个结点上时，与该结点相连的所有边将都可以被了">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://private.codecogs.com/gif.latex?Dp_%7Bi,0/1%7DDpi,0/1">
<meta property="og:image" content="https://private.codecogs.com/gif.latex?%5Cbegin%7Bcases%7DSon_i%5Cneq%20%5Cvarnothing%5C%5C%5C%20%5C%5C%20%5Cdisplaystyle%20Dp_%7Bi,0%7D=%5Csum_%7Bj%5Cin%20Son_i%7DDp_%7Bj,1%7D%5C%5C%5C%20%5C%5C%5Cdisplaystyle%20Dp_%7Bi,1%7D=1+%5Csum_%7Bj%5Cin%20Son_i%7Dmin(Dp_%7Bj,0%7D,Dp_%7Bj,1%7D)%5Cend%7Bcases%7D%25u23A9%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23A8%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23A7%25u200BSoni%25u200B%25u2260%25u2205%20Dpi,0%25u200B=j%25u2208Soni%25u200B%25u2211%25u200BDpj,1%25u200B%20Dpi,1%25u200B=1+j%25u2208Soni%25u200B%25u2211%25u200Bmin(Dpj,0%25u200B,Dpj,1%25u200B)%25u200B">
<meta property="og:image" content="https://private.codecogs.com/gif.latex?%5Cbegin%7Bcases%7DSon_i=%5Cvarnothing%5C%5CDp_%7Bi,0%7D=0%5C%5CDp_%7Bi,1%7D=1%5Cend%7Bcases%7D%25u23A9%25u23AA%25u23A8%25u23AA%25u23A7%25u200BSoni%25u200B=%25u2205Dpi,0%25u200B=0Dpi,1%25u200B=1%25u200B">
<meta property="og:image" content="https://private.codecogs.com/gif.latex?Son_i=%5Cvarnothing%20Soni%25u200B=%25u2205">
<meta property="og:image" content="https://private.codecogs.com/gif.latex?%5Cdisplaystyle%20%5Csum_%7Bj%5Cin%20Son_i%7DDp_%7Bj,1%7D=%5Csum_%7Bj%5Cin%20Son_i%7Dmin(Dp_%7Bj,0%7D,Dp_%7Bj,1%7D)=0j%25u2208Soni%25u200B%25u2211%25u200BDpj,1%25u200B=j%25u2208Soni%25u200B%25u2211%25u200Bmin(Dpj,0%25u200B,Dpj,1%25u200B)=0">
<meta property="og:image" content="https://private.codecogs.com/gif.latex?%5Cbegin%7Bcases%7D%5Cdisplaystyle%20Dp_%7Bi,0%7D=0+%5Csum_%7Bj%5Cin%20Son_i%7DDp_%7Bj,1%7D%5C%5C%5C%20%5C%5C%5Cdisplaystyle%20Dp_%7Bi,1%7D=1+%5Csum_%7Bj%5Cin%20Son_i%7Dmin(Dp_%7Bj,0%7D,Dp_%7Bj,1%7D)%5Cend%7Bcases%7D%25u23A9%25u23AA%25u23AA%25u23AA%25u23AA%25u23A8%25u23AA%25u23AA%25u23AA%25u23AA%25u23A7%25u200BDpi,0%25u200B=0+j%25u2208Soni%25u200B%25u2211%25u200BDpj,1%25u200B%20Dpi,1%25u200B=1+j%25u2208Soni%25u200B%25u2211%25u200Bmin(Dpj,0%25u200B,Dpj,1%25u200B)%25u200B">
<meta property="article:published_time" content="2023-12-05T16:11:44.337Z">
<meta property="article:modified_time" content="2023-12-05T16:18:51.593Z">
<meta property="article:author" content="Chiam">
<meta property="article:tag" content="算法，安全">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://private.codecogs.com/gif.latex?Dp_%7Bi,0/1%7DDpi,0/1">
  
  
  
  <title>『算法-ACM竞赛-动态规划-树形DP』洛谷2016战略游戏（树形DP） - Chiam 的个人主页</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="/css/custom.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":"❡"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":2},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Chiam&#39;s Blogs</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="『算法-ACM竞赛-动态规划-树形DP』洛谷2016战略游戏（树形DP）"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-12-06 00:11" pubdate>
          2023年12月6日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          1.3k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          12 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">『算法-ACM竞赛-动态规划-树形DP』洛谷2016战略游戏（树形DP）</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="『算法-ACM-竞赛-动态规划-树形-DP』洛谷-2016-战略游戏（树形-DP）"><a href="#『算法-ACM-竞赛-动态规划-树形-DP』洛谷-2016-战略游戏（树形-DP）" class="headerlink" title="『算法-ACM 竞赛-动态规划-树形 DP』洛谷 2016 战略游戏（树形 DP）"></a>『算法-ACM 竞赛-动态规划-树形 DP』洛谷 2016 战略游戏（树形 DP）</h1><h1 id="洛谷-2016-战略游戏（树形-DP）"><a href="#洛谷-2016-战略游戏（树形-DP）" class="headerlink" title="洛谷 2016 战略游戏（树形 DP）"></a>洛谷 2016 战略游戏（树形 DP）</h1><h3 id="题目描述"><a href="#题目描述" class="headerlink" title="题目描述"></a>题目描述</h3><p>Bob 喜欢玩电脑游戏，特别是战略游戏。但是他经常无法找到快速玩过游戏的办法。现在他有个问题。</p>
<p>他要建立一个古城堡，城堡中的路形成一棵树。他要在这棵树的结点上放置最少数目的士兵，使得这些士兵能了望到所有的路。</p>
<p>注意，某个士兵在一个结点上时，与该结点相连的所有边将都可以被了望到。</p>
<p>请你编一程序，给定一树，帮 Bob 计算出他需要放置最少的士兵.</p>
<h3 id="输入格式"><a href="#输入格式" class="headerlink" title="输入格式"></a>输入格式</h3><p>第一行 N，表示树中结点的数目。</p>
<p>第二行至第 N+1 行，每行描述每个结点信息，依次为：该结点标号 i，k(后面有 k 条边与结点 I 相连)。</p>
<p>接下来 k 个数，分别是每条边的另一个结点标号 r1，r2，…，rk。</p>
<p>对于一个 n(0&lt;n&lt;&#x3D;1500)个结点的树，结点标号在 0 到 n-1 之间，在输入数据中每条边只出现一次。</p>
<h3 id="输出格式"><a href="#输出格式" class="headerlink" title="输出格式"></a>输出格式</h3><p>输出文件仅包含一个数，为所求的最少的士兵数目。</p>
<p>例如，对于如下图所示的树：</p>
<pre><code class="hljs">       2
      /
0---1
      \
       3
</code></pre>
<p>答案为 1（只要一个士兵在结点 1 上）。</p>
<h3 id="输入输出样例"><a href="#输入输出样例" class="headerlink" title="输入输出样例"></a>输入输出样例</h3><p><strong>输入 #1</strong>复制</p>
<pre><code class="hljs">4
0 1 1
1 2 2 3
2 0
3 0
</code></pre>
<p><strong>输出 #1</strong>复制</p>
<pre><code class="hljs">1
</code></pre>
<h3 id="【分析】"><a href="#【分析】" class="headerlink" title="【分析】"></a><strong>【分析】</strong></h3><p>题目相当于需要求覆盖这颗树需要的最小点数</p>
<p>用 <img src="https://private.codecogs.com/gif.latex?Dp_%7Bi,0/1%7DDpi,0/1" srcset="/img/loading.gif" lazyload alt="Dp_{i,0/1}Dpi,0/1">​ 表示在这棵树中，<strong>以 ii 为根节点的子树</strong>在<strong>选&#x2F;不选根节点</strong>的情况下，覆盖这棵树所有边需要的<strong>最小点数</strong></p>
<p>所以，当不选这个节点 ii 时，则所有 以<strong>其子节点为根节点</strong>的子树 都必选根节点</p>
<p>当选择这个节点 ii 时，它能连接到所有的子节点，所以 以<strong>其子节点为根节点</strong>的子树 可以选则其根节点，也可以不选</p>
<p>归纳成方程组，可能更容易理解：</p>
<p><img src="https://private.codecogs.com/gif.latex?%5Cbegin%7Bcases%7DSon_i%5Cneq%20%5Cvarnothing%5C%5C%5C%20%5C%5C%20%5Cdisplaystyle%20Dp_%7Bi,0%7D=%5Csum_%7Bj%5Cin%20Son_i%7DDp_%7Bj,1%7D%5C%5C%5C%20%5C%5C%5Cdisplaystyle%20Dp_%7Bi,1%7D=1+%5Csum_%7Bj%5Cin%20Son_i%7Dmin(Dp_%7Bj,0%7D,Dp_%7Bj,1%7D)%5Cend%7Bcases%7D%25u23A9%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23A8%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23AA%25u23A7%25u200BSoni%25u200B%25u2260%25u2205%20Dpi,0%25u200B=j%25u2208Soni%25u200B%25u2211%25u200BDpj,1%25u200B%20Dpi,1%25u200B=1+j%25u2208Soni%25u200B%25u2211%25u200Bmin(Dpj,0%25u200B,Dpj,1%25u200B)%25u200B" srcset="/img/loading.gif" lazyload alt="\begin{cases}Son_i\neq \varnothing\\\ \\ \displaystyle Dp_{i,0}=\sum_{j\in Son_i}Dp_{j,1}\\\ \\\displaystyle Dp_{i,1}=1+\sum_{j\in Son_i}min(Dp_{j,0},Dp_{j,1})\end{cases}⎩⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎧​Soni​≠∅ Dpi,0​=j∈Soni​∑​Dpj,1​ Dpi,1​=1+j∈Soni​∑​min(Dpj,0​,Dpj,1​)​"></p>
<p>其中，Son_iSoni​ 为 ii 的子节点集合</p>
<p>显然，边界为</p>
<p><img src="https://private.codecogs.com/gif.latex?%5Cbegin%7Bcases%7DSon_i=%5Cvarnothing%5C%5CDp_%7Bi,0%7D=0%5C%5CDp_%7Bi,1%7D=1%5Cend%7Bcases%7D%25u23A9%25u23AA%25u23A8%25u23AA%25u23A7%25u200BSoni%25u200B=%25u2205Dpi,0%25u200B=0Dpi,1%25u200B=1%25u200B" srcset="/img/loading.gif" lazyload alt="\begin{cases}Son_i=\varnothing\\Dp_{i,0}=0\\Dp_{i,1}=1\end{cases}⎩⎪⎨⎪⎧​Soni​=∅Dpi,0​=0Dpi,1​=1​"></p>
<p>如果定义 <img src="https://private.codecogs.com/gif.latex?Son_i=%5Cvarnothing%20Soni%25u200B=%25u2205" srcset="/img/loading.gif" lazyload alt="Son_i=\varnothing Soni​=∅">时<img src="https://private.codecogs.com/gif.latex?%5Cdisplaystyle%20%5Csum_%7Bj%5Cin%20Son_i%7DDp_%7Bj,1%7D=%5Csum_%7Bj%5Cin%20Son_i%7Dmin(Dp_%7Bj,0%7D,Dp_%7Bj,1%7D)=0j%25u2208Soni%25u200B%25u2211%25u200BDpj,1%25u200B=j%25u2208Soni%25u200B%25u2211%25u200Bmin(Dpj,0%25u200B,Dpj,1%25u200B)=0" srcset="/img/loading.gif" lazyload alt="\displaystyle \sum_{j\in Son_i}Dp_{j,1}=\sum_{j\in Son_i}min(Dp_{j,0},Dp_{j,1})=0j∈Soni​∑​Dpj,1​=j∈Soni​∑​min(Dpj,0​,Dpj,1​)=0"></p>
<p>递推式及其边界便能写在一起了：</p>
<p><img src="https://private.codecogs.com/gif.latex?%5Cbegin%7Bcases%7D%5Cdisplaystyle%20Dp_%7Bi,0%7D=0+%5Csum_%7Bj%5Cin%20Son_i%7DDp_%7Bj,1%7D%5C%5C%5C%20%5C%5C%5Cdisplaystyle%20Dp_%7Bi,1%7D=1+%5Csum_%7Bj%5Cin%20Son_i%7Dmin(Dp_%7Bj,0%7D,Dp_%7Bj,1%7D)%5Cend%7Bcases%7D%25u23A9%25u23AA%25u23AA%25u23AA%25u23AA%25u23A8%25u23AA%25u23AA%25u23AA%25u23AA%25u23A7%25u200BDpi,0%25u200B=0+j%25u2208Soni%25u200B%25u2211%25u200BDpj,1%25u200B%20Dpi,1%25u200B=1+j%25u2208Soni%25u200B%25u2211%25u200Bmin(Dpj,0%25u200B,Dpj,1%25u200B)%25u200B" srcset="/img/loading.gif" lazyload alt="\begin{cases}\displaystyle Dp_{i,0}=0+\sum_{j\in Son_i}Dp_{j,1}\\\ \\\displaystyle Dp_{i,1}=1+\sum_{j\in Son_i}min(Dp_{j,0},Dp_{j,1})\end{cases}⎩⎪⎪⎪⎪⎨⎪⎪⎪⎪⎧​Dpi,0​=0+j∈Soni​∑​Dpj,1​ Dpi,1​=1+j∈Soni​∑​min(Dpj,0​,Dpj,1​)​"></p>
<p>答案看了以上大牛的解析</p>
<pre><code class="hljs">#include&lt;iostream&gt;
#include&lt;algorithm&gt;
#include&lt;queue&gt;
#include&lt;cstring&gt;
using namespace std;
vector &lt;int&gt; edge[1510];
int dp[2][1510],n,x,y,sum[1510],z;
void solve(int u,int fa)
&#123;
    for(int i=0;i&lt;edge[u].size();i++)
    &#123;
        int v=edge[u][i];
        if(v==fa)continue;
        solve(v,u);
        dp[0][u]+=dp[1][v];
        dp[1][u]+=min(dp[1][v],dp[0][v]);
    &#125;
    dp[1][u]++;
&#125;
int main()
&#123;
    cin&gt;&gt;n;
    for(int i=1;i&lt;=n;i++)
    &#123;
        cin&gt;&gt;x&gt;&gt;sum[x];
        for(int i=1;i&lt;=sum[x];i++)
        &#123;
            cin&gt;&gt;z;
            edge[x].push_back(z);
            edge[z].push_back(x);
        &#125;
    &#125;
    solve(0,0);
    int ans=min(dp[0][0],dp[1][0]);
    cout&lt;&lt;ans;
    return 0;
&#125;
</code></pre>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E7%AE%97%E6%B3%95/" class="category-chain-item">算法</a>
  
  
    <span>></span>
    
  <a href="/categories/%E7%AE%97%E6%B3%95/ACM%E7%AB%9E%E8%B5%9B/" class="category-chain-item">ACM竞赛</a>
  
  
    <span>></span>
    
  <a href="/categories/%E7%AE%97%E6%B3%95/ACM%E7%AB%9E%E8%B5%9B/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/" class="category-chain-item">动态规划</a>
  
  
    <span>></span>
    
  <a href="/categories/%E7%AE%97%E6%B3%95/ACM%E7%AB%9E%E8%B5%9B/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/%E6%A0%91%E5%BD%A2DP/" class="category-chain-item">树形DP</a>
  
  

  

  

  

      </span>
    
  
</span>

    </div>
  
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>『算法-ACM竞赛-动态规划-树形DP』洛谷2016战略游戏（树形DP）</div>
      <div>http://example.com/2023/12/06/『算法-ACM竞赛-动态规划-树形DP』洛谷2016战略游戏（树形DP）/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Chiam</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年12月6日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8E%E7%AE%97%E6%B3%95-ACM%E7%AB%9E%E8%B5%9B-%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92-%E6%A0%91%E5%BD%A2DP%E3%80%8F%E6%B4%9B%E8%B0%B7P1122%E6%9C%80%E5%A4%A7%E5%AD%90%E6%A0%91%E5%92%8C%E6%A0%91%E5%BD%A2DP%E5%88%9D%E6%AD%A5/" title="『算法-ACM竞赛-动态规划-树形DP』洛谷P1122最大子树和树形DP初步">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">『算法-ACM竞赛-动态规划-树形DP』洛谷P1122最大子树和树形DP初步</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8E%E7%AE%97%E6%B3%95-ACM%E7%AB%9E%E8%B5%9B-%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92-%E6%A0%91%E5%BD%A2DP%E3%80%8F%E6%B4%9B%E8%B0%B72014%E9%80%89%E8%AF%BE%EF%BC%88%E6%A0%91%E5%BD%A2DP)%E6%A0%91%E5%BD%A2%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98/" title="『算法-ACM竞赛-动态规划-树形DP』洛谷2014选课（树形DP)树形背包问题">
                        <span class="hidden-mobile">『算法-ACM竞赛-动态规划-树形DP』洛谷2014选课（树形DP)树形背包问题</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"fIfc7WqUDZohlQuPc2lz5mJy-MdYXbMMI","appKey":"zjlAG3ZA3o4cBHVAkjzc2Z20","path":"window.location.pathname","placeholder":"留言仅限讨论，禁止广告等行为","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"https://fifc7wqu.api.lncldglobal.com","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <meta name="referrer" content="no-referrer" /> <footer id="footer" role="contentinfo"> <div class="divider"> <div class="wall"></div> <img class="animals" src="/img/footer_animals_new.png" srcset="/img/loading.gif" lazyload alt="Footer Animals"> </div> <div class="container" data-index="450"> <p> <a href="https://chiamzhang.github.io" target="_blank">DogEgg</a> <i class="iconfont icon-love"></i> <a href="#" target="_blank">LittePig</a> </p> <p> Powered by  <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-pen"></i> Theme  <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> </p> </div> </footer> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>




  
<script src="/js/love.js"></script>
<script src="/js/funnyTitle.js"></script>
<script src="/js/backTop.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxuehua.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"left","width":150,"height":150,"hOffset":20,"vOffset":0},"mobile":{"show":false,"scale":0.5},"react":{"opacity":0.9},"log":false});</script></body>
</html>
